﻿using DotNetCore.CAP;
using Shop.IServices;

namespace Shop.WebApi
{
    /// <summary>
    /// CAP订阅者
    /// </summary>
    public class CapEventSubscriber : ICapSubscribe
    {
        private readonly IEventHandleAppService _eventHandleAppService;
        /// <summary>
        /// 
        /// </summary>
        public CapEventSubscriber(IEventHandleAppService eventHandleAppService)
        {
            _eventHandleAppService = eventHandleAppService;
        }

        /// <summary>
        /// 佣金
        /// </summary>
        /// <param name="orderId"></param>
        [CapSubscribe("Order.Payment")]
        public async void CalculateCommission(long orderId)
        {
            await _eventHandleAppService.CalculateCommission(orderId);
        }

        /// <summary>
        /// 用户等级检测
        /// </summary>
        /// <param name="userIds"></param>
        /// <returns></returns>
        [CapSubscribe("User.Upgrade")]
        public async Task UserUpgradeCheck(List<long> userIds)
        {
            await _eventHandleAppService.UserUpgradeCheck(userIds);
        }

        /// <summary>
        /// 推送到ERP
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [CapSubscribe("Order.Push")]
        public async Task PushOrderToERP(long orderId)
        {
            await _eventHandleAppService.PushOrderToERP(orderId);
        }
    }
}
